<?php

/**
 * 公众号类
 */

include_once __DIR__ . "/../tools/wxBizMsgCrypt/wxBizMsgCrypt.php";
include_once __DIR__ .'/../Base.php';
include_once __DIR__ . '/../linhePDO.php';
include_once __DIR__ . '/../system.UIShujuZhongxin.php';

class C公众号 extends Base {
    public function __construct() {
        parent::__construct();
    }

    /**
     * @根据不同的公众号id返回不同的欢迎语
     */
    public static function ff查找公众号欢迎语($公众号id) {
        $公众号欢迎语 = self::$pdo->selectColumns('public_serv_accounts',array('关注信息'),array('id'=>$公众号id));
        return $公众号欢迎语['关注信息'];
    }

    /*
     * @根据公众号ID获取公众号openID
     */
    public static function ff根据公众号id查询公众号openID($公众号ID) {
        $公众号信息 = pdo()->selectColumns('public_serv_accounts',array('公众号openID'),array('id'=>$公众号ID));
        return $公众号信息['公众号openID'];
    }

    /**
     * @@根据不同的公众号id返回不同的帮助语
     */
    public static function ff查找公众号帮助语($公众号id) {
        $公众号欢帮助语句 = self::$pdo->selectColumns('public_serv_accounts',array('name,帮助信息'),array('id'=>$公众号id));
        if($公众号欢帮助语句['帮助信息']) {
            return $公众号欢帮助语句['帮助信息'];
        }else {
            return '感谢您关注'.$公众号欢帮助语句['name'];
        }
    }

    /**
     * @根据用户openID取到公众号id
     */
    public static function fg根据openID获取公众号id($openID) {
        $公众号id = self::$pdo->selectColumns('用户',array('公众号ID'),array('openID'=>$openID));
        return $公众号id['公众号ID'];
    }
    public  function f检查公众号是否加密($appid){
        $是否加密 =self::$pdo->selectColumns('public_serv_accounts',array('是否加密'),array('id'=>$appid));
        return $是否加密['是否加密'];
    }
    public   function f解码解密url($appid,$sReqMsgSig,$sReqTimeStamp,$sReqNonce,$encrypt_type,$sReqData){


        $encodingAesKey = self::$pdo->selectColumns('public_serv_accounts',array('EncodingAESKey'),array('id'=>$appid));
        $token =self::$pdo->selectColumns('public_serv_accounts',array('token'),array('id'=>$appid));
        $corpId = self::$pdo->selectColumns('public_serv_accounts',array('app_id'),array('id'=>$appid));

        $pc = new WXBizMsgCrypt($token['token'],$encodingAesKey['EncodingAESKey'], $corpId['app_id']);

        $sMsg = "";  // 解析之后的明文

         if ($encrypt_type == 'aes'){
            $decryptMsg = "";  //解密后的明文
            $errCode = $pc->DecryptMsg($sReqMsgSig, $sReqTimeStamp, $sReqNonce, $sReqData, $sMsg);


             if ($errCode == 0) {
                return   $sMsg;
         }

          }

    }
    public  function  f解码加密url($appid,$sRespData, $sReqTimeStamp, $sReqNonce){
        $encodingAesKey = self::$pdo->selectColumns('public_serv_accounts',array('EncodingAESKey'),array('id'=>$appid));
        $token =self::$pdo->selectColumns('public_serv_accounts',array('token'),array('id'=>$appid));
        $corpId = self::$pdo->selectColumns('public_serv_accounts',array('app_id'),array('id'=>$appid));

        $pc = new WXBizMsgCrypt($token['token'],$encodingAesKey['EncodingAESKey'], $corpId['app_id']);
        $sEncryptMsg = ""; //xml格式的密文
        $errCode = $pc->EncryptMsg($sRespData, $sReqTimeStamp, $sReqNonce,$sEncryptMsg);

        if ($errCode == 0) {
            return   $sEncryptMsg;
        }

    }

}